/*
 * Copyright 2007-2009 Thomas Krause (thomas@berlin-reloaded.de)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.gidoo.cms.editor.edit;

import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.model.PropertyModel;

/**
 * 
 * @author <a href="mailto:thomas@berlin-reloaded.de">Thomas Krause</a>
 */
public class SimpleEditorComponent extends EditorComponent
{
  private Form form;
  private TextArea txtEdit;

  private String text = "";
  
  public SimpleEditorComponent()
  {
    form = new Form("form");
    txtEdit = new TextArea("txtEdit", new PropertyModel(this, "text"));
    txtEdit.setMarkupId("txtEdit_SimpleEditorComponent");
    txtEdit.setEscapeModelStrings(false);
    txtEdit.setOutputMarkupId(true);
    form.add(txtEdit);
    add(form);    
    this.setOutputMarkupId(true);
  }

  
  @Override
  public String getText()
  {
    if(text == null)
    {
      text = "";
    }
    return text;
  }

  @Override
  public void setText(String newText)
  {
    if(newText == null)
    {
      text = "";
    }
    else
    {
      text = newText;
    }
  }

  @Override
  public boolean isPreviewFunctionNeeded()
  {
    return true;
  }

  @Override
  public void enableComponents(boolean enable)
  {
    form.setEnabled(enable);
    txtEdit.setEnabled(enable);
  }

  @Override
  public String getDefaultXml()
  {
    return  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
          + "<gidootml>\n\n"
          + "</gidootml>";
  }
  
  
  
}
